{% extends 'web/layout/manage.html' %}
{% load static %}
{% block css %}
    <link rel="stylesheet" href="{% static 'web/css/button.css' %}">
    <link rel="stylesheet" href="{% static 'web/css/project.css' %}">

{% endblock %}
{% block content %}
    <div class="container-fluid project">
        <a class="btn btn-primary" data-toggle="modal" data-target="#myModal">
            <i class="fa fa-plus-circle" aria-hidden="true"></i>
            新建项目
        </a>

        <div class="panel panel-default project-star">
          <div class="panel-heading"><i class="fa fa-star" aria-hidden="true"></i> 星标项目</div>
          <div class="panel-body">
              {% for item in project_dict.star %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.value.id %}" class="title"
                       style="background-color: {{ item.value.get_color_display }}">{{ item.value.name }}</a>
                    <div class="info">
                        <div>

                            <a href="{% url 'project_unstar' project_type=item.type project_id=item.value.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color:#f0ad4e"></i>
                            </a>
                            <span>{{ item.value.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.value.join_count }}</span>
                        </div>
                    </div>
                </div>
              {% endfor %}
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading"><i class="fa fa-list" aria-hidden="true"></i> 我创建的项目</div>
          <div class="panel-body">
              {% for item in project_dict.my %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.id%}" class="title"
                       style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='my' project_id=item.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>
                </div>
              {% endfor %}
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading"><i class="fa fa-handshake-o" aria-hidden="true"></i> 我参与的项目</div>
          <div class="panel-body">
              {% for item in project_dict.join %}
                <div class="item">
                    <a href="{% url 'dashboard' project_id=item.id%}" class="title"
                       style="background-color: {{ item.get_color_display }}">{{ item.name }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='join' project_id=item.id %}">
                                <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5"></i>
                            </a>
                            <span>{{ item.creator.username }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ item.join_count }}</span>
                        </div>
                    </div>
                </div>
              {% endfor %}
          </div>
        </div>

    </div>

    <!-- 模态框 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">新建项目</h4>
          </div>
          <div class="modal-body">
              <!-- 表单 -->
              <form id="addForm">
              {% csrf_token %}
                  {% for field in form %}
                      <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }}
                        <span class="error-msg"></span>
                      </div>
                  {% endfor %}
                </form>

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关 闭</button>
            <button id="btnSubmit" type="button" class="btn btn-primary">保 存</button>
          </div>
        </div>
      </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(function(){
            bindSubmit();
        });

        function bindSubmit(){
            $('#btnSubmit').click(function (){
                $('.error-msg').empty()
                $.ajax({
                    url:"{% url 'project_list' %}",
                    type:"POST",
                    data:$('#addForm').serialize(),
                    dataType:"JSON",
                    success:function (res){
                        if(res.status){
                            location.href=location.href
                            //location.reload()
                        }else {
                            $.each(res.error,function (key,value){
                                $("#id_" + key).next().text(value[0]);
                            })
                        }
                    }
                })
            })
        }

    </script>

{% endblock %}






